﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace LIMS.Windows
{
    public class Validations
    {
        // Function To test for Alphabets. 
        private bool IsAlpha(String strToCheck)
        {
            Regex objAlphaPattern = new Regex("[^a-zA-Z]");
            return !objAlphaPattern.IsMatch(strToCheck);
        }
        // Function to Check for AlphaNumeric.
        private bool IsAlphaNumeric(String strToCheck)
        {
            Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
            return !objAlphaNumericPattern.IsMatch(strToCheck);
        }
        public static bool IsPhone(String strToCheck)
        {
            string pattern = @"((\(\d{3,4}\)|\d{3,4}-)\d{4,9}(-\d{1,5}|\d{0}))|(\d{4,12})";
            Regex objAlphaPattern = new Regex(pattern);
            return objAlphaPattern.IsMatch(strToCheck);

        }
        public static bool IsFax(String strToCheck)
        {
            //string pattern = @"/([\(\+])?([0-9]{1,3}([\s])?)?([\+|\(|\-|\)|\s])?([0-9]{2,4})([\-|\)|\.|\s]([\s])?)?([0-9]{2,4})?([\.|\-|\s])?([0-9]{4,8})/";
            string pattern = @"^\+[0-9]{1,3}\([0-9]{3}\)[0-9]{7}$";
            Regex objAlphaPattern = new Regex(pattern);
            return objAlphaPattern.IsMatch(strToCheck);

        }

        public static bool IsMobile(String strToCheck)
        {
            //string pattern = @"^07([\d]{3})[(\D\s)]?[\d]{3}[(\D\s)]?[\d]{3}$";
            string pattern = @"^\d+$";
            Regex objAlphaPattern = new Regex(pattern);
            return objAlphaPattern.IsMatch(strToCheck);
            
        }
        /// <summary>
        /// Check  is text box empty t.
        /// </summary>
        /// <param name="inputString"></param>
        /// <returns></returns>
        public static bool IsEmpty(string inputString)
        {
           bool bIsEmpty = false;
            bIsEmpty  = (string.IsNullOrEmpty(inputString))?true:false;
            return bIsEmpty;
        }
        /// <summary>
        /// IsCmbboxDefaultValue
        /// </summary>
        /// <param name="selectedValue"></param>
        /// <returns></returns>
        public static bool IsCmbboxDefaultValue(string selectedValue)
        {
            bool IsDefaultValue = false;
            IsDefaultValue = (selectedValue.Equals("X") || selectedValue.Equals("0")) ? true : false;
            return IsDefaultValue;
        }

        public static bool IsDate(string sDate)
        {
            try
            {
                DateTime dt = DateTime.Parse(sDate);
                if (dt != DateTime.MinValue && dt != DateTime.MaxValue)
                    return true;

                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
